package com.allqj.sfx.ddd.member.interfaces.restful.admin;

import com.allqj.sfx.application.dto.DictDTO;
import com.allqj.sfx.application.dto.TableColumnDTO;
import com.allqj.sfx.ddd.member.application.dto.FlowDefDTO;
import com.allqj.sfx.ddd.member.application.service.AdminFlowApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author sjw
 * @className FlowController
 * @date 2022/7/22 14:14
 * @description: 审批流
 */
@Api(tags = "会员管理-管理端-审批配置")
@RestController
@RequestMapping("/v1/member/admin/flow")
public class AdminFlowController {

    private final AdminFlowApplicationService adminFlowApplicationService;

    public AdminFlowController(AdminFlowApplicationService adminFlowApplicationService) {
        this.adminFlowApplicationService = adminFlowApplicationService;
    }

    @ApiOperation(value = "管理端-审批配置-审批模块字典")
    @GetMapping("/moduleTypes")
    public List<DictDTO> moduleType() {
        return adminFlowApplicationService.moduleTypes();
    }

    @ApiOperation(value = "管理端-审批配置-审批模块-功能字典")
    @GetMapping("/{moduleId}/functionTypes")
    public List<DictDTO> functionType(@PathVariable Integer moduleId) {
        return adminFlowApplicationService.functionTypes(moduleId);
    }

    @ApiOperation(value = "管理端-审批配置-审批模块-审批人类型字典")
    @GetMapping("/approverTypes")
    public List<DictDTO> approverTypes() {
        return adminFlowApplicationService.approverTypes();
    }

    @ApiOperation(value = "管理端-审批配置-列表表头")
    @GetMapping("/pageHeader")
    public List<TableColumnDTO> pageHeader() {
        return adminFlowApplicationService.pageHeader();
    }

    @ApiOperation(value = "管理端-审批配置-新增审批")
    @PostMapping("/def")
    public Integer addDef(@RequestBody @Valid FlowDefDTO flowDefDTO) {
        return adminFlowApplicationService.addFlowDef(flowDefDTO);
    }

    @ApiOperation(value = "管理端-审批配置-修改审批")
    @PutMapping("/def")
    @Validated
    public Integer modifyDef(@RequestBody @Valid FlowDefDTO flowDefDTO) {
        return adminFlowApplicationService.modifyFlowDef(flowDefDTO);
    }


    @ApiOperation(value = "管理端-审批配置-启动流程实例")
    @GetMapping("/instance/{code}/{extParam}")
    public Integer instance(@PathVariable Integer code, @PathVariable String extParam) {
        return adminFlowApplicationService.instance(code, extParam);
    }

    @ApiOperation(value = "管理端-审批配置-流程实例-通过")
    @GetMapping("/pass/{instanceId}")
    public Integer pass(@PathVariable Integer instanceId) {
        return adminFlowApplicationService.pass(instanceId);
    }

    @ApiOperation(value = "管理端-审批配置-流程实例-驳回")
    @GetMapping("/reject/{instanceId}")
    public Integer reject(@PathVariable Integer instanceId) {
        return adminFlowApplicationService.reject(instanceId);
    }
}
